/** Fenetre d'acquisition des donnees de creation d'un cadran Plan */
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.border.Border;

public class FenetreAcquisition {
	// fenetre cree et fenetre mere
	private JDialog fenetreAcquisition;
	private PagePrincipale pageP;
	
	// boutons radio pour choix type d'heure
	private ButtonGroup typeHeure;  
	private JRadioButton hSolaire; 
	private JRadioButton hLegale;
	
	// zones d'acquisitions
	private Choice listeFuseaux;
	private JTextField lat;
	private JTextField f;
	private JTextField longu;
	private JTextField larg;
	private JTextField angVert;
	private JTextField angHor;
	private JTextField xVal;
	private JTextField yVal;
	private JTextField zVal;
	
	/** Ouverture de la fenetre d'acquisition des donnees pour un cadran plan 
	 * 
	 * @param fenetrePrincipale la JFrame de la page principale
	 * @param horizontal un booleen a true si le cadran plan est horizontal, false s'il est vertical 
	 */
	public FenetreAcquisition(PagePrincipale pageP){
		this.pageP = pageP;
		initialisation();
		placerComposant();
	}
	
	/** creation de la fenetre */
	private void initialisation(){
		fenetreAcquisition = new JDialog(pageP.getFenetrePrincipale());
		fenetreAcquisition.setBounds(300,100,700,400);
		fenetreAcquisition.setTitle("Creer un cadran plan");
		fenetreAcquisition.setVisible(true);
	}

	/** placement et organisation des composants */
	private void placerComposant(){
		Border bordure = BorderFactory.createLineBorder(Color.black);
		
		// organisation verticale
		JPanel page = new JPanel();
	    page.setLayout(new BoxLayout(page, BoxLayout.PAGE_AXIS));
	    
	    /////////////////
	    // Type d'heure
	    /////////////////
	    JPanel panHeure = new JPanel();
 	    panHeure.setLayout(new BoxLayout(panHeure, BoxLayout.LINE_AXIS));
 	    panHeure.setPreferredSize(new Dimension(700,50));
 	    panHeure.add(Box.createRigidArea(new Dimension(200,0)));
 	    
 	    typeHeure = new ButtonGroup();  
	    hSolaire = new JRadioButton("Heure solaire"); 
	    hSolaire.setPreferredSize(new Dimension(150,50));
	    hLegale = new JRadioButton("Heure legale"); 
	    hSolaire.setPreferredSize(new Dimension(150,50));
	    hSolaire.setSelected(true);
	    
	    hSolaire.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				//labFuseau.setEnabled(false);
		    	listeFuseaux.setEnabled(false);
		    	pageP.setHeureSolaire(true);
			    fenetreAcquisition.repaint();
			} 
		});
	    
	    hLegale.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				//labFuseau.setEnabled(true);
		    	listeFuseaux.setEnabled(true);
		    	pageP.setHeureSolaire(false);
		    	fenetreAcquisition.repaint();
			}
		});
	    
	    typeHeure.add(hSolaire);
	    typeHeure.add(hLegale);
	    panHeure.add(hSolaire);
 	    panHeure.add(Box.createRigidArea(new Dimension(100,0)));
 	    panHeure.add(hLegale);
 	    panHeure.add(Box.createRigidArea(new Dimension(100,0)));
 	  	
 	    page.add(Box.createRigidArea(new Dimension(0,10)));
 	  	page.add(panHeure);
 	  	page.add(Box.createRigidArea(new Dimension(0,10)));
 	
 	  	panHeure.add(Box.createRigidArea(new Dimension(200,0)));
		
		///////////////////////////////
		//	Coordonnees geographiques
		///////////////////////////////
		JPanel coordPanneau = new JPanel();
		JLabel titre = new JLabel("<html><u>Coordonnees geographiques</u></html>",JLabel.CENTER);
		coordPanneau.setLayout(new BoxLayout(coordPanneau, BoxLayout.LINE_AXIS));
	    coordPanneau.setPreferredSize(new Dimension(700,150));
	    coordPanneau.add(titre);
	    
	    // ajouts dans l'organisation verticale
	    page.add(Box.createRigidArea(new Dimension(0,10)));
	    page.add(coordPanneau);
	    page.add(Box.createRigidArea(new Dimension(0,10)));
	    
	    JPanel latFusPanneau = new JPanel();
	    latFusPanneau.setPreferredSize(new Dimension(700,50));
	    latFusPanneau.setLayout(new BoxLayout(latFusPanneau, BoxLayout.LINE_AXIS));
	    
	    // latitude
	    JLabel latitude = new JLabel("Latitude :");
	    latitude.setPreferredSize(new Dimension(75,30));
	    latFusPanneau.add(Box.createRigidArea(new Dimension(75,0)));
	    latFusPanneau.add(latitude);
	    
	    lat = new JTextField();
	    lat.setHorizontalAlignment(JTextField.CENTER);
	    lat.setBackground(Color.orange);
	    lat.setPreferredSize(new Dimension(65,50));
	    lat.setBorder(bordure);
	    latFusPanneau.add(Box.createRigidArea(new Dimension(25,0)));
	    latFusPanneau.add(lat);
	    
	    JLabel deg = new JLabel("degres");
	    deg.setPreferredSize(new Dimension(50,50));
	    latFusPanneau.add(Box.createRigidArea(new Dimension(10,0)));
	    latFusPanneau.add(deg);
	    latFusPanneau.add(Box.createRigidArea(new Dimension(50,0)));
	    
	    // fuseau horaire	
	    JLabel labFuseau = new JLabel("Fuseau horaire :");
	    labFuseau.setPreferredSize(new Dimension(125,50));
	    latFusPanneau.add(Box.createRigidArea(new Dimension(50,0)));
 		latFusPanneau.add(labFuseau);
	    
	    listeFuseaux = new Choice();
	    listeFuseaux.setPreferredSize(new Dimension(100,50));
	    for(int i=-12;i<=12;i++){					
			listeFuseaux.addItem("GMT "+i);
	    }
	    
	    listeFuseaux.setBackground(Color.orange);
	    latFusPanneau.add(listeFuseaux);
	    latFusPanneau.add(Box.createRigidArea(new Dimension(75,0)));
	    
	    if(pageP.isHeureSolaire()){
	    	listeFuseaux.setEnabled(false);
		    fenetreAcquisition.repaint();
	    }
	    
	    // ajout dans l'organisation verticale
	    page.add(latFusPanneau);
	    page.add(Box.createRigidArea(new Dimension(0,10)));  
	    
	    /////////////////////////
	    // Definition du plateau
	    /////////////////////////
	    JPanel dimPanneau = new JPanel();
		JLabel dimensions = new JLabel("<html><u>Definition du plateau</u></html>",JLabel.CENTER);
		dimPanneau.setLayout(new BoxLayout(dimPanneau, BoxLayout.LINE_AXIS));
	    dimPanneau.setPreferredSize(new Dimension(700,150));
	    dimPanneau.add(dimensions);
		
		
		// longueur
		JPanel longPanneau = new JPanel();
		longPanneau.setPreferredSize(new Dimension(300,50));
		longPanneau.setLayout(new BoxLayout(longPanneau, BoxLayout.LINE_AXIS));
	    JLabel longueur = new JLabel("Longueur :");
	    longueur.setPreferredSize(new Dimension(100,50));
	    longPanneau.add(Box.createRigidArea(new Dimension(75,0)));
	    longPanneau.add(longueur);
	    
	    longu = new JTextField();
	    longu.setHorizontalAlignment(JTextField.CENTER);
	    longu.setBackground(Color.orange);
	    longu.setPreferredSize(new Dimension(50,50));
	    longu.setBorder(bordure);
	    longPanneau.add(longu);
	    
	    JLabel metre = new JLabel("m");
	    metre.setPreferredSize(new Dimension(35,50));
	    longPanneau.add(Box.createRigidArea(new Dimension(15,0)));
	    longPanneau.add(metre);
	    longPanneau.add(Box.createRigidArea(new Dimension(25,0)));
	    
	    // largeur
	    JPanel largPanneau = new JPanel();
		largPanneau.setPreferredSize(new Dimension(300,100));
		largPanneau.setLayout(new BoxLayout(largPanneau, BoxLayout.LINE_AXIS));
	    JLabel largeur = new JLabel("Largeur :");
	    largeur.setPreferredSize(new Dimension(100,50));
	    largPanneau.add(Box.createRigidArea(new Dimension(75,0)));
	    largPanneau.add(largeur);
	    
	    larg = new JTextField();
	    larg.setHorizontalAlignment(JTextField.CENTER);
	    larg.setBackground(Color.orange);
	    larg.setPreferredSize(new Dimension(50,50));
	    larg.setBorder(bordure);
	    largPanneau.add(larg);
	    
	    JLabel metr2 = new JLabel("m");
	    metr2.setPreferredSize(new Dimension(35,50));
	    largPanneau.add(Box.createRigidArea(new Dimension(15,0)));
	    largPanneau.add(metr2);
	    largPanneau.add(Box.createRigidArea(new Dimension(25,0)));
	    
	    // inclinaison verticale
	    JPanel angleVertPanneau = new JPanel();
		angleVertPanneau.setPreferredSize(new Dimension(400,50));
		angleVertPanneau.setLayout(new BoxLayout(angleVertPanneau, BoxLayout.LINE_AXIS));
	    JLabel angleVert = new JLabel("Inclinaison verticale :");
	    angleVert.setPreferredSize(new Dimension(175,50));
	   	angleVertPanneau.add(angleVert);
	    
	    angVert = new JTextField();
	    angVert.setHorizontalAlignment(JTextField.CENTER);
	    angVert.setBackground(Color.orange);
	    angVert.setPreferredSize(new Dimension(75,50));
	    angVert.setBorder(bordure);
	    angleVertPanneau.add(Box.createRigidArea(new Dimension(25,0)));
	    angleVertPanneau.add(angVert);
	    
	    JLabel deg2 = new JLabel("degres");
	    deg2.setPreferredSize(new Dimension(50,50));
	    angleVertPanneau.add(Box.createRigidArea(new Dimension(10,0)));
	    angleVertPanneau.add(deg2);
	    angleVertPanneau.add(Box.createRigidArea(new Dimension(65,0)));
	    
	    
	    // inclinaison horizontale
	    JPanel angleHorizPanneau = new JPanel();
		angleHorizPanneau.setPreferredSize(new Dimension(400,100));
		angleHorizPanneau.setLayout(new BoxLayout(angleHorizPanneau, BoxLayout.LINE_AXIS));
	    JLabel labAngleHor = new JLabel("Inclinaison horizontale :");
	    labAngleHor.setPreferredSize(new Dimension(175,50));
	   	angleHorizPanneau.add(labAngleHor);
	    
	    angHor = new JTextField();
	    angHor.setHorizontalAlignment(JTextField.CENTER);
	    angHor.setBackground(Color.orange);
	    angHor.setPreferredSize(new Dimension(75,50));
	    angHor.setBorder(bordure);
	    angleHorizPanneau.add(Box.createRigidArea(new Dimension(25,0)));
	    angleHorizPanneau.add(angHor);
	   
	    JLabel deg3 = new JLabel("degres");
	    deg3.setPreferredSize(new Dimension(50,50));
	    angleHorizPanneau.add(Box.createRigidArea(new Dimension(10,0)));
	    angleHorizPanneau.add(deg3);
	    angleHorizPanneau.add(Box.createRigidArea(new Dimension(65,0)));
	    
	    
	    /* *********************************************************** */
	    JPanel ligne1 = new JPanel();
	    ligne1.setLayout(new BoxLayout(ligne1, BoxLayout.LINE_AXIS));
	    ligne1.setPreferredSize(new Dimension(700,50));
	    /* *********************************************************** */
	    JPanel ligne2 = new JPanel();
	    ligne2.setLayout(new BoxLayout(ligne2, BoxLayout.LINE_AXIS));
	    ligne2.setPreferredSize(new Dimension(700,50));
	    /* *********************************************************** */
	    
	    // Organisation sur la page
	    page.add(dimPanneau);
	    page.add(Box.createRigidArea(new Dimension(0,10)));
	    ligne1.add(longPanneau);
	    ligne1.add(angleVertPanneau);
	    page.add(ligne1);
	    page.add(Box.createRigidArea(new Dimension(0,10)));
	    
	    ligne2.add(largPanneau);
	    ligne2.add(angleHorizPanneau);
	    page.add(Box.createRigidArea(new Dimension(0,10)));
	    page.add(ligne2);
	    page.add(Box.createRigidArea(new Dimension(0,10)));
	    
	    ///////////////////////
	    //Coordonnees du style
	    ///////////////////////	
  		JPanel stylePanneau = new JPanel();
  		JLabel styleT = new JLabel("<html><u>Coordonnees du style</u></html>",JLabel.CENTER);
		stylePanneau.setLayout(new BoxLayout(stylePanneau, BoxLayout.LINE_AXIS));
	    stylePanneau.setPreferredSize(new Dimension(700,150));
	    
	    JPanel coordStyPanneau = new JPanel();
  	    coordStyPanneau.setPreferredSize(new Dimension(700,50));
  	    coordStyPanneau.setLayout(new BoxLayout(coordStyPanneau, BoxLayout.LINE_AXIS));
	    stylePanneau.add(styleT);
  		
  		// x coordonnee de l'Ouest
  	    JLabel x = new JLabel("X :");
  	    x.setPreferredSize(new Dimension(25,50));
  	  	coordStyPanneau.add(Box.createRigidArea(new Dimension(100,0)));
  	    coordStyPanneau.add(x);
  	    coordStyPanneau.add(Box.createRigidArea(new Dimension(15,0)));
  	    
  	    xVal = new JTextField();
  	    xVal.setHorizontalAlignment(JTextField.CENTER);
  	    xVal.setBackground(Color.orange);
  	    xVal.setPreferredSize(new Dimension(50,50));
  	    xVal.setBorder(bordure);
  	    coordStyPanneau.add(xVal);
  	    
  	    JLabel metre3 = new JLabel("m");
  	    metre3.setPreferredSize(new Dimension(25,50));
  	    coordStyPanneau.add(Box.createRigidArea(new Dimension(10,0)));
  	    coordStyPanneau.add(metre3);
  	    coordStyPanneau.add(Box.createRigidArea(new Dimension(25,0)));
  	    
  	    // Y coordonnee du Sud
	    JLabel y = new JLabel("Y :");
	    y.setPreferredSize(new Dimension(25,50));
	    coordStyPanneau.add(Box.createRigidArea(new Dimension(50,0)));
	    coordStyPanneau.add(y);
	    coordStyPanneau.add(Box.createRigidArea(new Dimension(15,0)));
	    
	    yVal = new JTextField();
	    yVal.setHorizontalAlignment(JTextField.CENTER);
	    yVal.setBackground(Color.orange);
	    yVal.setPreferredSize(new Dimension(50,50));
	    yVal.setBorder(bordure);
	    coordStyPanneau.add(yVal);
	    
	    JLabel metre4 = new JLabel("m");
	    metre4.setPreferredSize(new Dimension(25,50));
	    coordStyPanneau.add(Box.createRigidArea(new Dimension(10,0)));
	    coordStyPanneau.add(metre4);
	    coordStyPanneau.add(Box.createRigidArea(new Dimension(25,0)));
	    
	    // Z coordonnee de la normale
  	    JLabel z = new JLabel("Z :");
  	    z.setPreferredSize(new Dimension(25,50));
  	    coordStyPanneau.add(Box.createRigidArea(new Dimension(50,0)));
  	    coordStyPanneau.add(z);
  	    coordStyPanneau.add(Box.createRigidArea(new Dimension(15,0)));
  	    
  	    zVal = new JTextField();
  	    zVal.setHorizontalAlignment(JTextField.CENTER);
  	    zVal.setBackground(Color.orange);
  	    zVal.setPreferredSize(new Dimension(50,50));
  	    zVal.setBorder(bordure);
  	    coordStyPanneau.add(zVal);
  	    
  	    JLabel metre5 = new JLabel("m");
  	    metre5.setPreferredSize(new Dimension(25,50));
  	    coordStyPanneau.add(Box.createRigidArea(new Dimension(10,0)));
  	    coordStyPanneau.add(metre5);
  	    coordStyPanneau.add(Box.createRigidArea(new Dimension(75,0)));
  	  
  	    // ajouts dans l'organisation verticale
  	    page.add(stylePanneau);
	    page.add(Box.createRigidArea(new Dimension(0,10)));
	    page.add(coordStyPanneau);
	    page.add(Box.createRigidArea(new Dimension(0,10)));
	    
	    ///////////
	    // Boutons
	    ///////////
	    JPanel boutonPanneau = new JPanel();
  	    boutonPanneau.setPreferredSize(new Dimension(400,100));
  	    boutonPanneau.setLayout(new BoxLayout(boutonPanneau, BoxLayout.LINE_AXIS));
	    
  	    JButton annuler = new JButton("Annuler");
  	    boutonPanneau.add(annuler);
  	    annuler.addActionListener(new ActionListener(){
  	    	public void actionPerformed(ActionEvent e){
  	    		fenetreAcquisition.dispose();
  	    	}
  	    });
  	    
  	  	boutonPanneau.add(Box.createRigidArea(new Dimension(100,0)));
  	    JButton valider = new JButton("Valider");
  	    boutonPanneau.add(valider);
  	    valider.addActionListener(new EcouteurValiderPlan(pageP, this));
  	    
  	    // ajouts dans l'organisation verticale
  	    page.add(Box.createRigidArea(new Dimension(0,30)));
  	    page.add(boutonPanneau);
  	    page.add(Box.createRigidArea(new Dimension(0,10)));
  	    
  	    // ajouter le tout sur la JDialog
	    fenetreAcquisition.getContentPane().add(page);
	}

	///////////////////////////
	// Get et Set des fenetres
	///////////////////////////
	
	public JDialog getFenetreAcquisition() {
		return fenetreAcquisition;
	}

	public void setFenetreAcquisition(JDialog fenetreAcquisition) {
		this.fenetreAcquisition = fenetreAcquisition;
	}
	
	public PagePrincipale getPageP() {
		return pageP;
	}

	public void setPageP(PagePrincipale pageP) {
		this.pageP = pageP;
	}

	//////////////////////////////////////
	// Get et Set des zones d'acquisition
	//////////////////////////////////////
	
	public JTextField getLat() {
		return lat;
	}

	public void setLat(JTextField l) {
		this.lat = l;
	}

	public JTextField getF() {
		return f;
	}

	public void setF(JTextField f) {
		this.f = f;
	}

	public JTextField getLongu() {
		return longu;
	}

	public void setLongu(JTextField longu) {
		this.longu = longu;
	}

	public JTextField getLarg() {
		return larg;
	}

	public void setLarg(JTextField larg) {
		this.larg = larg;
	}
	
	public JTextField getAngVert() {
		return angVert;
	}
	
	public JTextField getAngHor() {
		return angHor;
	}

	public void setAngleVert(JTextField ang) {
		this.angVert = ang;
	}
	
	public void setAngleHor(JTextField ang) {
		this.angHor = ang;
	}

	public JTextField getxVal() {
		return xVal;
	}

	public void setxVal(JTextField xVal) {
		this.xVal = xVal;
	}

	public JTextField getyVal() {
		return yVal;
	}

	public void setyVal(JTextField yVal) {
		this.yVal = yVal;
	}

	public JTextField getzVal() {
		return zVal;
	}

	public void setzVal(JTextField zVal) {
		this.zVal = zVal;
	}
}